import request from '@/utils/request'

// 查询订餐管理列表
export function listOrder(query) {
  return request({
    url: '/mealorder/order/list',
    method: 'get',
    params: query
  })
}
// 查询订餐管理VO列表
export function voList(query) {
  return request({
    url: '/mealorder/order/voList',
    method: 'get',
    params: query
  })
}
// 查询订餐管理详细
export function getOrder(id) {
  return request({
    url: '/mealorder/order/' + id,
    method: 'get'
  })
}

// 新增订餐管理
export function addOrder(data) {
  return request({
    url: '/mealorder/order',
    method: 'post',
    data: data
  })
}

// 修改订餐管理
export function updateOrder(data) {
  return request({
    url: '/mealorder/order',
    method: 'put',
    data: data
  })
}

// 新增修改餐食状态的接口
export function alterMealStatus(id, status) {
  return request({
    url: '/h5/alterStatus',
    method: 'get',
    params: {
      id: id,
      status: status
    }
  })
}

// 删除订餐管理（支持单个或批量删除）
export function delOrder(id) {
  // 如果id是数组，则转换为逗号分隔的字符串
  const url = Array.isArray(id) 
    ? '/mealorder/order/' + id.join(',') 
    : '/mealorder/order/' + id;
  
  return request({
    url: url,
    method: 'delete'
  })
}
// 根据员工ID和培训ID删除订餐管理
export function delOrdersByEmpAndTraining(empId, trainingId) {
  return request({
    url: `/mealorder/order/emp/${empId}/training/${trainingId}`,
    method: 'delete'
  })
}
export function importTemplate() {
  return request({
    url: '/mealorder/order/importTemplate',
    method: 'post',
    responseType: 'blob'
  })
}

// 导入数据
export function importData(data) {
  return request({
    url: '/mealorder/order/importData',
    method: 'post',
    data: data
  })
}

// 新增导入订餐表格数据函数
export function importMealOrderTable(data) {
  return request({
    url: '/mealorder/order/importMealOrderTable',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}


// 发送邮件API
export function sendEmail(data) {
  return request({
    url: '/mealorder/order/sendEmail',
    method: 'post',
    data: data
  })
}

// 发送自定义邮件
export function sendCustomEmail(data) {
  return request({
    url: '/mealorder/order/sendCustomEmail',
    method: 'post',
    data: data
  })
}

export function exportOrder(params) {
  return request({
    url: '/mealorder/order/export',
    method: 'get',
    params: params,
    responseType: 'blob'
  });
}
